package com.woniuxy.business.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.business.config.KillProducer;
import com.woniuxy.business.service.CouponService;
import com.woniuxy.commons.entity.Coupon;
import com.woniuxy.commons.entity.QueryEntity;
import com.woniuxy.commons.utils.ResStatus;
import com.woniuxy.commons.utils.ResponseResult;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author 雷珉
 * @date 2022年06月08日 16:41
 */
@RestController
@RequestMapping("/business/coupon")
public class CouponController {
    @Resource
    private CouponService couponService;

    @GetMapping("/")
    public ResponseResult<List<Coupon>> findAll(){
        return couponService.findAll();
    }

    @PostMapping("/condition")
    public ResponseResult<PageInfo<Coupon>> findAllByCondition(@RequestBody QueryEntity<Coupon> queryEntity){
        return couponService.findAllByCondition(queryEntity);
    }

    @GetMapping("/{id}")
    public ResponseResult<Coupon> findOne(@PathVariable("id") int id){
        return couponService.findOne(id);
    }

    @PostMapping("/")
    public ResponseResult addOne(@RequestBody Coupon Coupon){
        return couponService.addOne(Coupon);
    }

    @PutMapping("/")
    public ResponseResult updateOne(@RequestBody Coupon Coupon){
        return couponService.updateOne(Coupon);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteOne(@PathVariable("id") int id){
        return couponService.deleteOne(id);
    }

    @PostMapping("/batchDel")
    public ResponseResult deleteBatch(@RequestBody int[] ids){
        return couponService.deleteBatch(ids);
    }

    @PutMapping("/active")
    public ResponseResult active(@RequestBody Coupon Coupon){
        return couponService.active(Coupon);
    }

    @GetMapping("/{id}/{userId}")
    public ResponseResult getCoupon(@PathVariable("id") int id,@PathVariable("userId") int userId){
        return couponService.getCoupon(id,userId);
    }
}

